package com.flashdeck.utils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import junit.framework.TestCase;

import org.apache.commons.lang.math.RandomUtils;

public class DecksTagsTest extends TestCase {

	public void testGetAvailableTaqs() {
		DecksTags decksTags = new DecksTags();
		decksTags.addDeck("1", new HashSet<String>(Arrays.asList(new String[] {"a", "b", "c"})));
		decksTags.addDeck("2", new HashSet<String>(Arrays.asList(new String[] {"b", "c", "d"})));
		decksTags.addDeck("3", new HashSet<String>(Arrays.asList(new String[] {"a", "d"})));
		
		Set<String> availableTaqs = decksTags.getAvailableTaqs(new HashSet<String>(Arrays.asList(new String[] {"a"})));
		System.out.println(availableTaqs);
	}

	public void testGetDecks() {
		Set<String> tags = new HashSet<String>(Arrays.asList(new String[] {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w"}));
		DecksTags decksTags = getSampleDecksTags(10000, tags);
		Set<String> availableTaqs = decksTags.getAvailableTaqs(new HashSet<String>(Arrays.asList(new String[] {"a", "b", "c"})));
		System.out.println(availableTaqs);
	}
	
	public DecksTags getSampleDecksTags(int decks, Set<String> tags) {
		DecksTags result = new DecksTags();
		
		for (int i = 0; i < decks; i++) {
			result.addDeck(Integer.toString(i), getRandomTags(RandomUtils.nextInt(tags.size() / 3), tags));
		}
		
		return result;
	}
	
	public Set<String> getRandomTags(int count, Set<String> tags) {
		Set<String> result = new HashSet<String>(count);
		String[] tagsArray = tags.toArray(new String[0]);
		
		for (int i = 0; i < count; i ++) {
			result.add(tagsArray[RandomUtils.nextInt(tags.size())]);
		}
		
		return result;
	}

}
